//
//  hZTiJbJLCFMineMoneyLogViewControllernOFYEf.m
//  qcb_ios
//
//  Created by Ji on 2018/8/30.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "hZTiJbJLCFMineMoneyLogViewControllernOFYEf.h"
#import "hphaptJLCFMineMoneyLogResultModeldhpqVh.h"
#import "sHkPtEJLCFMineRequestozAYZs.h"
#import "OjuJZGJLCFMineMoneyLogCellUgozLC.h"

@interface hZTiJbJLCFMineMoneyLogViewControllernOFYEf ()
{
    NSInteger _pageNumber;
}

@property (nonatomic, strong) NSMutableArray *DSAEKhmoneyArrJHumFd;

@end

@implementation hZTiJbJLCFMineMoneyLogViewControllernOFYEf

- (NSMutableArray *)DSAEKhmoneyArrJHumFd
{
    if (!_DSAEKhmoneyArrJHumFd) {
        _DSAEKhmoneyArrJHumFd = [NSMutableArray array];
    }
    return _DSAEKhmoneyArrJHumFd;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationBar.title = @"资金记录";
    self.tableView.backgroundColor = QTZ_Gray237;
    
    [self loadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadData
{
    [self.DSAEKhmoneyArrJHumFd removeAllObjects];
    _pageNumber = 1;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    [params setSafeObject:@"tender" forKey:@"type"];
    
    [sHkPtEJLCFMineRequestozAYZs moneyLogWithParams:params loadingInView:self.view success:^(hphaptJLCFMineMoneyLogResultModeldhpqVh *money) {
        [self hideNoMoreDataNotice];
        if (money.data.count > 0) {
            [self.DSAEKhmoneyArrJHumFd addObjectsFromArray:money.data];
            [self configHeaderView];
        } else {
            self.tableView.tableHeaderView = nil;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endRefresh];
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
    
}

- (void)configHeaderView
{
    
    UIView *rRHNlxheaderViewfJQeRl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 52)];
    self.tableView.tableHeaderView = rRHNlxheaderViewfJQeRl;
    
    UILabel *LufDjKnameLabelRjatWG = [UILabel labelWithText:@"交易名称" textColor:QTZ_Gray102 font:FONT(15)];
    LufDjKnameLabelRjatWG.centerX = FULL_WIDTH / 6;
    LufDjKnameLabelRjatWG.centerY = 26;
    [rRHNlxheaderViewfJQeRl addSubview:LufDjKnameLabelRjatWG];
    
    UILabel *GAvcnIamountLabelMphKiM = [UILabel labelWithText:@"交易金额" textColor:QTZ_Gray102 font:FONT(15)];
    GAvcnIamountLabelMphKiM.centerX = FULL_WIDTH / 2;
    GAvcnIamountLabelMphKiM.centerY = LufDjKnameLabelRjatWG.centerY;
    [rRHNlxheaderViewfJQeRl addSubview:GAvcnIamountLabelMphKiM];
    
    UILabel *hnRcVmtimeLabelncDSPi = [UILabel labelWithText:@"交易时间" textColor:QTZ_Gray102 font:FONT(15)];
    hnRcVmtimeLabelncDSPi.centerX = FULL_WIDTH / 6 * 5;
    hnRcVmtimeLabelncDSPi.centerY = LufDjKnameLabelRjatWG.centerY;
    [rRHNlxheaderViewfJQeRl addSubview:hnRcVmtimeLabelncDSPi];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, 51, FULL_WIDTH - 20, 1)];
    line.backgroundColor = QTZ_Gray222;
    [rRHNlxheaderViewfJQeRl addSubview:line];
    
}

- (void)loadMoreData
{
    
    _pageNumber ++;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:@(_pageNumber) forKey:@"page"];
    [params setSafeObject:@"tender" forKey:@"type"];
    
    [sHkPtEJLCFMineRequestozAYZs moneyLogWithParams:params loadingInView:self.view success:^(hphaptJLCFMineMoneyLogResultModeldhpqVh *money) {
        if (money.data.count > 0) {
            
            [self.DSAEKhmoneyArrJHumFd addObjectsFromArray:money.data];
        } else {
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endLoadMore];
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endLoadMore];
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.DSAEKhmoneyArrJHumFd.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OjuJZGJLCFMineMoneyLogCellUgozLC *cell = [OjuJZGJLCFMineMoneyLogCellUgozLC dequeueReusableCellForTableView:tableView];
    cell.money = [self.DSAEKhmoneyArrJHumFd safeObjectAtIndex:indexPath.row];
    [cell reloadData];
    return cell;
    
}

@end
